local songqi = fk.CreateSkill{
  name = "rfenghou_3d18j__songqi",
}

songqi:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  prompt = "#rfenghou_3d18j__songqi",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    if #all_names == 0 then return end
    local names = player:getViewAsCardNames(songqi.name, all_names)
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if not self.interaction then return end
    local name = self.interaction.data
    if not name then return end
    local c = Fk:cloneCard(name)
    c.skillName = songqi.name
    return c
  end,
  before_use = function(self, player, use)
    player.room:removePlayerMark(player, "_rfenghou_3d18j__songqi-round")
  end,
  times = function(self, player)
    return player:getMark("_rfenghou_3d18j__songqi-round")
  end,
  enabled_at_play = function(self, player)
    return player:getMark("_rfenghou_3d18j__songqi-round") > 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:getMark("_rfenghou_3d18j__songqi-round") > 0
  end,
})
songqi:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return ((target.role_shown and target.role == "lord") or target == player) and player:hasSkill(songqi.name) and player:getMark("@rfenghou_3d18j__songqi") == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local num = room:askToNumber(player, {
      min = 1,
      max = player.hp,
      skill_name = songqi.name,
      prompt = "#rfenghou_3d18j__songqi-invoke",
    })
    if num then
      event:setCostData(self, { num = num, tos = { target } })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    room:setPlayerMark(player, "@rfenghou_3d18j__songqi", dat.num)
    room:setPlayerMark(player, "_rfenghou_3d18j__songqi-round", dat.num)
    room:setPlayerMark(player, "_rfenghou_3d18j__songqi_record-round", 1)
  end
})
songqi:addEffect(fk.EventPhaseStart, {
  is_delay_effect = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player.phase == Player.Play and player:getMark("@rfenghou_3d18j__songqi") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "@rfenghou_3d18j__songqi")
    player.room:addPlayerMark(player, "_rfenghou_3d18j__songqi_prohibit-phase")
  end
})
songqi:addEffect(fk.RoundEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("_rfenghou_3d18j__songqi_record-round") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "_rfenghou_3d18j__songqi_record-round", 0)
    if player:getMark("_rfenghou_3d18j__songqi-round") > 0 then
      for _, to in ipairs(room:getAlivePlayers()) do
        room:loseHp(to, 1, songqi.name)
      end
    end
  end
})
songqi:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    if player.phase == Player.Play and player:getMark("_rfenghou_3d18j__songqi_prohibit-phase") ~= 0 then
      return card.trueName == "slash"
    end
  end
})

Fk:loadTranslationTable{
  ["rfenghou_3d18j__songqi"] = "嵩泣",
  [":rfenghou_3d18j__songqi"] = "你或主公受到伤害后，你可声明不大于你体力值的数字，令你接下来等量个出牌阶段无法使用【杀】、此技能无法发动直到你等量个出牌阶段结束，且本轮内可以视为使用等量张基本牌。本轮结束时，若你以此法使用基本牌的次数小于声明数，所有角色失去1点体力。",
  ["#rfenghou_3d18j__songqi"] = "嵩泣：视为使用一张基本牌",

  ["#rfenghou_3d18j__songqi-invoke"] = "嵩泣：你可声明不大于你体力值的数字，令你接下来等量个出牌阶段无法使用【杀】，且本轮内可以视为使用等量张基本牌",

  ["@rfenghou_3d18j__songqi"] = "嵩泣",
}

return songqi
